from django.http import response, HttpResponse, JsonResponse
from django.shortcuts import render, redirect

# Create your views here.
from django.urls import reverse


def myindex_handler(request):
    return HttpResponse('hello,ismyindex')


def re_index_handler(request,num):
    return HttpResponse(num)


def user_handler(request,username):
    return HttpResponse('hello,%s'%username)


def reverse_handler(request):
    print(reverse('mytest:index'))#无参数
    print(reverse('mytest:reindex',args=(1234,)))

    return HttpResponse('reverse')


def request_handler(request):
    print(request.method)
    print(request.path)
    print(request.META['REMOTE_ADDR'])
    print(request.META['CONTENT_TYPE'])#请求正文mime类型,HTML,普通文本,json
    print(request.META)
    for i in request.META.keys():
        print('%s = %s'%(i,request.META[i]))
    return HttpResponse("hello,mytest!")


def response_handler(request):
    return HttpResponse(
        content='HttpResponse',     #响应题
        content_type='text/plain',  #mime类型
        status=500  #状态码
    )


def jsonres_handler(request):
    return JsonResponse(
        {'edu':'stu',
         'name':'孔泽均'},
       json_dumps_params={'ensure_ascii':False}  #可以让中文在页面正常输出
    )


def redirect_handler(request):
    # return redirect('/mytest/')
    return redirect(reverse('mytest:index'))